package de.dhbw.tinf11b.vfb;

import java.util.LinkedList;
import java.util.List;

import de.dhbw.tinf11b.vfb.exceptions.CourseNotFoundException;

public class CourseManager {
	
	private static CourseManager instance = null;
	/**
	 * Singleton-Pattern: returns the course manager instance.
	 * @return
	 */
	public static CourseManager getInstance() {
		if (instance == null) {
			instance = new CourseManager();
		}
		return instance;
	}
	
	
	private List<Course> courses;
	
	private CourseManager() {
		this.courses = new LinkedList<Course>();
	}
	
	public List<Course> getCourses() {
		return courses;
	}
	
	public Course getCourseByName(String name) throws CourseNotFoundException {
		for(Course course : this.courses) {
			if(course.getName() == name) {
				return course;
			}
		}
		
		throw new CourseNotFoundException();
	}

	public void addCourse(String name, int year, String room, Curriculum curriculum, String courseDirector) {
		this.courses.add(new Course(name, year, room, curriculum, courseDirector));
	}
}
